{% extends "publisher/_publisher_layout.html" %}

{% block title %}
Register new Snap name
{% endblock %}

{% block content %}
<div class="p-strip">

  {% if conflict %}
    <div class="u-fixed-width">
      <h1 class="p-heading--two"><strong>{{ snap_name }}</strong> is already taken</h1>
    </div>
  {% else %}
    <div class="u-fixed-width">
      <h1 class="p-heading--two">Register snap</h1>
    </div>
  {% endif %}

  {% if conflict %}
    <div class="u-fixed-width">
      <div class="p-notification--caution">
        <p class="p-notification__response">
          Another publisher already registered <strong>{{ snap_name }}</strong>. You can <a href="/register-name-dispute?snap-name={{ snap_name }}">file a dispute</a> to request a transfer of ownership or register a new name below.
        </p>
      </div>
    </div>
  {% endif %}

  {% if already_owned %}
    <div class="u-fixed-width">
      <div class="p-notification--caution">
        <p class="p-notification__response">
          You already own '<a href="/account/snaps/{{ snap_name }}/listing"><strong>{{ snap_name }}</strong></a>'.
        </p>
      </div>
    </div>
  {% endif %}

  {% if reserved %}
    <div class="u-fixed-width">
      <div class="p-notification--caution">
        <p class="p-notification__response">
          '<strong>{{ snap_name }}</strong>' is reserved. You can <a href="/request-reserved-name?snap_name={{ snap_name }}&store={{ store }}&is_private={{ is_private }}">request a reserved name</a> or register a new name below.
        </p>
      </div>
    </div>
  {% endif %}

  {% if not conflict %}
    <div class="u-fixed-width">
      <p>Before you can push your snap to the store, its name must be registered</p>
    </div>
  {% endif %}

  {% if errors %}
    <div class="u-fixed-width">
      {% for error in errors %}
        <div class="p-notification--caution">
          <p class="p-notification__response">
            {{ error.message }}
          </p>
        </div>
      {% endfor %}
    </div>
  {% endif %}

  <form method="POST" action="/account/register-snap" class="u-no-margin--top">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>

    {% if available_stores %}
      <div class="row">
        <div class="col-8">
          <label for="snap-store">Store</label>
          <div class="p-form-validation__field">
            <select name="store" id="snap-store">
              <option value="ubuntu" checked="checked">Global</option>
              {% for store in available_stores %}
                <option value="{{ store.id }}">{{ store.name }}</option>
              {% endfor %}
            </select>
          </div>
        </div>
      </div>
    {% endif %}

    <div class="row">
      <div class="col-8">
        <div class="p-form-validation">
          <label for="snap-name">Snap name</label>
          <div class="p-form-validation__field">
            <input class="p-form-validation__input" type="text" name="snap-name" id="snap-name" required maxlength="64" value="{{ snap_name }}" />
          </div>
        </div>
        <div class="p-form-validation">
          <label for="public">Snap privacy</label>
          <p class="p-form-help-text">This can be changed at any time after the initial upload</p>
          <div class="p-form-validation__field">
            <input type="radio" name="is_private" value="public" class="p-form-validation__input" id="public" {% if not is_private %} checked {% endif %}>
            <label for="public">Public</label>
            <input type="radio" name="is_private" value="private" class="p-form-validation__input" id="private" {% if is_private %} checked {% endif %}>
            <label for="private">Private <span class="p-form-help-text">Snap is hidden in stores and only accessible by the publisher and collaborators</span></label>
          </div>
        </div>
      </div>
    </div>

    <div class="u-fixed-width">
        <hr/>
    </div>

    <div class="u-fixed-width">
      <div class="u-clearfix u-align--right">
        <input type="submit" class="p-button--positive u-no-margin--top u-float-right" value="Register"/>
        <a class="p-button--neutral u-float-right" href="/account/snaps">Cancel</a>
      </div>
    </div>
  </form>
</div>
{% endblock %}
